﻿<Windows:DataWindow x:Class="MyMediaStuff.UI.Windows.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Windows="clr-namespace:Catel.Windows;assembly=Catel.Windows"
                    xmlns:ViewModels="clr-namespace:MyMediaStuff.UI.ViewModels"
                    xmlns:LocalControls="clr-namespace:MyMediaStuff.UI.Controls"
                    xmlns:Controls="clr-namespace:Catel.Windows.Controls;assembly=Catel.Windows"
                    x:TypeArguments="ViewModels:MainWindowViewModel"
                    SizeToContent="Manual" ShowInTaskbar="True" ResizeMode="CanResizeWithGrip" WindowState="Maximized" 
                    Icon="/Resources/Icons/Catel.ico">

    <!-- Resources -->
    <Windows:DataWindow.Resources>
    </Windows:DataWindow.Resources>

    <!-- Content -->
    <DockPanel LastChildFill="True">

        <Grid DockPanel.Dock="Top">
            <!-- Theme switching, not in view model because it has nothing to do with that -->
            <WrapPanel Orientation="Horizontal" VerticalAlignment="Center"
                   DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type Windows:DataWindow}}}">
                <Label Content="Theme" VerticalAlignment="Center" />
                <ComboBox SelectedItem="{Binding SelectedTheme}" ItemsSource="{Binding AvailableThemes}"
                      DisplayMemberPath="Name" VerticalAlignment="Center" />
            </WrapPanel>

            <Controls:LinkLabel ClickBehavior="OpenUrlInBrowser" Url="http://catel.codeplex.com" 
                                Content="http://catel.codeplex.com" HorizontalAlignment="Right" />
        </Grid>

        <DockPanel LastChildFill="True">
            <!-- Listbox with available media providers -->
            <ListBox DockPanel.Dock="Left" ItemsSource="{Binding MediaProviders}" SelectedItem="{Binding SelectedMediaProvider}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <Image Grid.Row="0" Source="{Binding LogoUri}" ToolTip="{Binding Name}" Width="128" Height="128" />
                            <TextBlock Grid.Row="1" Text="{Binding Name}" HorizontalAlignment="Center" FontSize="12" FontStyle="Italic" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <!-- Control that dynamically determines what user control to show, based on the selected provider -->
            <Control>
                <Control.Resources>
                    <!-- Home template -->
                    <ControlTemplate x:Key="homeTemplate">
                        <LocalControls:HomeView DataContext="{Binding SelectedMediaProvider}" />
                    </ControlTemplate>

                    <!-- Pictures template -->
                    <ControlTemplate x:Key="picturesTemplate">
                        <LocalControls:PicturesView DataContext="{Binding SelectedMediaProvider}" />
                    </ControlTemplate>

                    <!-- Videos template -->
                    <ControlTemplate x:Key="videosTemplate">
                        <LocalControls:VideosView DataContext="{Binding SelectedMediaProvider}" />
                    </ControlTemplate>
                </Control.Resources>

                <Control.Style>
                    <Style TargetType="{x:Type Control}">
                        <Style.Triggers>
                            <!-- Home trigger -->
                            <DataTrigger Binding="{Binding SelectedMediaProvider.Name}" Value="Home">
                                <Setter Property="Template" Value="{StaticResource homeTemplate}" />
                            </DataTrigger>

                            <!-- Pictures trigger -->
                            <DataTrigger Binding="{Binding SelectedMediaProvider.Name}" Value="Pictures">
                                <Setter Property="Template" Value="{StaticResource picturesTemplate}" />
                            </DataTrigger>

                            <!-- Videos trigger -->
                            <DataTrigger Binding="{Binding SelectedMediaProvider.Name}" Value="Videos">
                                <Setter Property="Template" Value="{StaticResource videosTemplate}" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Control.Style>
            </Control>
        </DockPanel>
    </DockPanel>
</Windows:DataWindow>
